Polymorphism for class types is supported by class-wide types. For each class type Objective VHDL provides an associated class-wide type. An instantiation of a class-wide type (polymorphic object) is allowed to change its actual type (i.e. its class membership) during runtime. From a conceptional point of view it can be said that a polymorphic object can "represent" objects of different classes during its lifetime.

If T denotes a class type, a polymorphic object can be instantiated:

variable t_poly:T'CLASS;

The 'CLASS attribute makes an object polymorphic. The type of the object t_poly can be T or any class type which is derived from T. The actual type of t_poly can be changed during runtime by assignment of a compatible type object.

To illustrate class type polymorphism we show the implementation and usage of the communication controller (of Chapter 4.3), which receives data packets and unifies their internal data representation.


type communication_controller is class
    class attribute
        loc_packet : unified_packet;
    for variable, signal
        procedure receive(
            i : in packet'CLASS);
    end for;
end class communication_controller;

type communication_controller is class body
  ...
  procedure receive(i : in packet'CLASS) is
  begin
      i.unify(loc_packet);
  end receive;
  ...
end communication_controller;

The receive method accepts data packets of type packet or a derived type as parameters. Inside the receive method it is not necessary to distinguish among the different types of data packets because the parameter i is a polymorphic object. The run-time system recognizes automatically the actual type of i and invokes the correct implementation of the unify method (dynamic binding).